/*
 * --------------------------------------------------------------------------------------
 * Additional information for A055897, A078707 and A243520 (By: R. J. Cano, Jun 27 2014)
 * --------------------------------------------------------------------------------------
 * (URL: http://oeis.org/w/images/5/5d/AdditionalInformationA078707andA243520.txt)
 * 
 * Dear user: This file is also a PARI-GP script.
 * The present content is subject to: The OEIS End-User License Agreement
 * (Visit http://oeis.org/wiki/The_OEIS_End-User_License_Agreement)
 * 
 * Specifically for A055897, see note #4.
 * 
 * Specifically for A078707, see note #3.
 * 
 * Description: Here is briefly exposed how by simple successive modifications from a main
 *              class of recurrence relations, at least four different sequences in apparently
 *              not related contexts are obtained. However: The underlying algorithmic structures
 *              for their calculations, are so similar that recall the group theory.
 * 
 */

/* The base for a class of additive recurrence relations. */
f0(n,v,i)=if(!n,i,f0(n-1,v,i)+v[1+n%2]);

/* Multiplicative analogue for f0() */
g0(n,v,i)=if(!n,i,g0(n-1,v,i)*v[1+n%2]);

/* It can be verified that ceil((x+1)/2) is identical to h(x) as defined below: */
h(x)=(x+(x%2))\2+!(x%2-!x)+!x;

/* By defining the following such that: even(x)+odd(x) == x+1 */
even(x)=ceil((x+1)/2);
odd(x)={my(z=even(x));x-z+1};
/*                   
 * Note 1. ...Therefore even(x) might be defined alternatively as even(x)=h(x);
 * 
 *         (It means of course: By replacing here the corresponding right-hand sides)
 */

/* An iterative version of f0 indeed is */
f1(x,v,i)={my(c=min(v[1],v[2]),w);w=vector(#v,j,v[j]-c);i+x*c+(even(x)-1)*w[1]+odd(x)*w[2]}

/* Now a possible iterative version "everything built-in" (**APPARENTLY an optimization) would be: */
f2(x,v,i)={my(c=min(v[1],v[2]),z=ceil((x+1)/2),w);w=vector(#v,j,v[j]-c);i+x*c+(z-1)*w[1]+(x-z+1)*w[2]}
/*                   
 * Note 2. f2() seems not much significant for A243520 since there
 *         are available other alternatives. However the knowledge
 *         about how to avoid the recursion in f0() might be 
 *         (appreciably) useful in general.
 */

/*
 * Note 3. g0(n,[1,n],1) is the same than A078707(n)
 * 
 *         Notice however it recalls the factorial of n.
 *         indeed, it was named initially by the author of this sourcecode:
 * 
 *         "The ceiling factorial" of n
 * 
 *         Due the similarity of the call:
 * 
 *                g0(n,[1,n],1)
 * 
 *         with:
 * 
 *                f0(n,[0,1],0)
 * 
 *         In the sense of being both based upon the corresponding
 *         neutral elements of their underlying operations.
 * 
 *         In fact there might exist at least three different ways of
 *         defining these objects, here they will be named respectively:
 * 
 *         "The ceiling factorial of the zeroth kind",
 * 
 *                 G0(n)= if(!n,1,g0(n-1,[1,n],1)*[1,n][1+n%2]);
 * 
 *                       ...which in fact actually is a power (A078707). 
 * 
 *         "The ceiling factorial of the first kind",
 *
 *                 G1(n)= if(!n,1,(g0(n-1,[1,n-1],1))*[1,n][1+n%2]);
 * 
 *         "The ceiling factorial of the second kind",
 *
 *                 G2(n)= if(!n,1,(g0(n-1,[n-1,1],1))*[n,1][1+n%2]);
 * 
 */

 G0(n)= if(!n,1,g0(n-1,[1,n],1)*[1,n][1+n%2]);
 G1(n)= if(!n,1,(g0(n-1,[1,n-1],1))*[1,n][1+n%2]);
 G2(n)= if(!n,1,(g0(n-1,[n-1,1],1))*[n,1][1+n%2]);

/*
 * Note 4. The product G1(n)*G2(n) is identical to A055897.
*/  

 G3(n)=G1(n)*G2(n);

/* The following GP-Pari stub of code gives the first 17 terms in A055897.

 G3(n)=G1(n)*G2(n);
 Q=vector(17,j,G3(j));
 print(Q);

   The resulting output should be:
  
[1, 2, 12, 108, 1280, 18750, 326592, 6588344, 150994944, 3874204890, 110000000000, 3423740047332, 115909305827328, 4240251492291542, 166680102383370240, 7006302246093750000, 313594649253062377472]

*/ 

/* Now: An alternative def. for ceil(n/2) or the sequence A110654 */
ceil2(x)=f2(x,[0,1],0);

/* Five alternative studied ways of getting A243520(n) */
a243520_0(n)=-5/4*(-1)^n+11*n/2+5/4;
a243520_1(n)=5*n+2*(n%2)+ceil(n/2);
a243520_2(n)=f0(n,[3,8],0);
a243520_3(n)=f1(n,[3,8],0);
a243520_4(n)=f2(n,[3,8],0);

/* And finally a bonus routine: Print the first terms in the correspondig sequence.
 * 
 * s=0 for a b-file, s=1 for a search field, both with u terms.
 * 
 */

bfileprinterA110654(u,s=0)=for(k=0,u,if(s,print1(","f2(k,[0,1],0)),print(k" "f2(k,[0,1],0))));

bfileprinterA243520(u,s=0)=for(k=0,u,if(s,print1(","f2(k,[3,8],0)),print(k" "f2(k,[3,8],0))));

bfileprinterA078707(u,s=0)=for(k=0,u,if(s,print1(","G0(k)),print(k" "G0(k))));

bfileprinterA055897(u,s=0)=for(k=0,u,if(s,print1(","G3(k)),print(k" "G3(k))));
